#ifndef _ONLINE_H_
#define _ONLINE_H_
#define MAX 10
struct Online{
	int socket[MAX];
	int id[MAX];
};
void init_online(struct Online * on)
{
	int i;
	for(i = 0;i<MAX;i++){
		(*on).socket[i] = -1;
		(*on).id[i] = -1;
	}
}
void add(struct Online *on,int socket,int id)
{
	int i;
	for(i=0;i<MAX;i++){
		if((*on).socket[i] == -1){
			(*on).socket[i] = socket;
			(*on).id[i] = id;
			return ;
		}
		if((*on).socket[i] == socket){
			(*on).socket[i] = socket;
			(*on).id[i] = id;
			return ;	
		}
	}
}
int find_socket(struct Online *on,int id)
{
	int i;
	for(i=0;i<MAX;i++){
		if((*on).id[i] == id)
			return ((*on).socket[i]);
	}
	return -1;
}
int find_id(struct Online *on,int socket)
{
	int i;
	for(i = 0;i<MAX;i++){
		if((*on).socket[i] == socket)
			return ((*on).id[i]);
	}
	return -1;
}
void dele_socket(struct Online *on,int socket)
{
	int i;
	for(i=0;i<MAX;i++){
		if((*on).socket[i] == socket){
			(*on).socket[i] = -1;
			(*on).id[i] = -1;
			return ;
		}
	}
}
#endif
